package com.example.zbh.dsliao.utils;

import android.content.Context;
import android.content.SharedPreferences;

import com.example.zbh.dsliao.application.App;

/**
 * 缓存
 */
public class PreferenceHelper {
    public static final String PREFERENCE_NAME = "saveInfo";
    private static PreferenceHelper mPreferenceHelper;
    private static SharedPreferences mSharedPreferences;
    private static SharedPreferences.Editor editor;

    //Key
    public static final String CURRENTUSER_USERNAME = "currentUser_userName";
    private static final String CURRENTUSER_AVATAR = "currentUser_avatar";
    private static final String NEW_NOTIFY = "new_notify";
    private static final String SHARED_KEY_CURRENTUSER_NICK = "SHARED_KEY_CURRENTUSER_NICK";
    private static final String SETTING_TYPEFACE = "typeface";
    private static final String SETTING_COLOR = "typecolor";
    private static final String SETTING_SIZE = "typesize";
    private static final String CURRENTUSERPSW = "psw";
    private static final String CHATBACKGROUND =  "chatbackground";


    private static String SHARED_KEY_CURRENTUSER_USERNAME = "SHARED_KEY_CURRENTUSER_USERNAME";
    private static String SHARED_KEY_CURRENTUSER_NICK_THREE = "SHARED_KEY_CURRENTUSER_NICK_THREE";
    private static String SHARED_KEY_CURRENTUSER_AVATAR = "SHARED_KEY_CURRENTUSER_AVATAR";



    private PreferenceHelper() {
        mSharedPreferences = App.getContext().getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
        editor = mSharedPreferences.edit();
    }

    public static PreferenceHelper getInstance() {
        if (mPreferenceHelper == null) {
            mPreferenceHelper = new PreferenceHelper();
        }
        return mPreferenceHelper;
    }

    //设置当前的用户名
    public void setCurrentUserName(String name) {
        editor.putString(CURRENTUSER_USERNAME, name).commit();
    }

    //取当前用户的用户名
    public String getCurrentUserName() {
            return mSharedPreferences.getString(CURRENTUSER_USERNAME, null);
    }
    //存入当前用户的密码
    public void setCurrentUserPsw(String psw){
        editor.putString(CURRENTUSERPSW, psw).commit();
    }
    //取出当前用户的密码
    public String getCurrentUserPsw(){
        return mSharedPreferences.getString(CURRENTUSERPSW, null);
    }
    //删除当前的用户名
    public void removeCurrentUserName(){
        editor.remove(CURRENTUSER_USERNAME).commit();
    }
    //删除当前的密码
    public void removeCurrentUserPsw(){
        editor.remove(CURRENTUSERPSW).commit();
    }



    //设置当前用户的头像
    public void setCurrentUserAvatar(String avater) {
        editor.putString(CURRENTUSER_AVATAR, avater).commit();
    }

    //取当前用户的头像
    public void getCurrentUserAvater() {
        mSharedPreferences.getString(CURRENTUSER_AVATAR, null);
    }

    //设置是否接受新消息提醒
    public void setNewNotify(boolean isChange) {
        editor.putBoolean(NEW_NOTIFY, isChange).commit();
    }

    //取当前用户设置是否新消息提醒
    public boolean getNewNotify() {
        return mSharedPreferences.getBoolean(NEW_NOTIFY, true);
    }

    //取当前
    public String getCurrentUserNick() {
        return mSharedPreferences.getString(SHARED_KEY_CURRENTUSER_NICK, null);
    }

    //设置头像缓存
    public void setCurrentUserNick(String nick) {
        editor.putString(SHARED_KEY_CURRENTUSER_NICK, nick);
        editor.commit();
    }

    public void setCurrentTextType(String text) {
        editor.putString(SETTING_TYPEFACE, text);
        editor.commit();
    }

    public String getCurrentTextType() {
        return mSharedPreferences.getString(SETTING_TYPEFACE, null);
    }

    public void setCurrentTextColor(String text) {
        editor.putString(SETTING_COLOR, text);
        editor.commit();
    }

    public String getCurrentuserTextColor() {
        return mSharedPreferences.getString(SETTING_COLOR, null);
    }

    public void setCurrentTextSize(String size) {
        editor.putString(SETTING_SIZE, size);
        editor.commit();
    }

    public String  getCurrentTextSize() {
        return mSharedPreferences.getString(SETTING_SIZE, null);
    }

    public void setCurrentGroupName(String id,String name){
        editor.putString(id, name);
        editor.commit();
    }
    public String getCurrentGroupName(String id){
        return mSharedPreferences.getString(id, null);
    }
    public void setCurrentGroupStatus(String id, boolean flag){
        editor.putBoolean(id, flag);
        editor.commit();

    }
    public boolean getCurrentGroupStatus(String id){
        return mSharedPreferences.getBoolean(id, false);
    }

    //存储当前的聊天背景
    public void setCurrentuserBackground(String userName , String backGroundName){
        editor.putString(CHATBACKGROUND + userName, backGroundName).commit();
    }
    public String getCurrentuserBackground(String userName){
        return mSharedPreferences.getString(CHATBACKGROUND + userName, null);
    }


    /**
     * 第三方的头像昵称  实验
     * **/
    public void setThreeCurrentUserNick(String nick) {
        editor.putString(SHARED_KEY_CURRENTUSER_NICK_THREE, nick);
        editor.commit();
    }

    public void setThreeCurrentUserAvatar(String avatar) {
        editor.putString(SHARED_KEY_CURRENTUSER_AVATAR, avatar);
        editor.commit();
    }

    public String getThreeCurrentUserNick() {
        return mSharedPreferences.getString(SHARED_KEY_CURRENTUSER_NICK_THREE, null);
    }

    public String getThreeCurrentUserAvatar() {
        return mSharedPreferences.getString(SHARED_KEY_CURRENTUSER_AVATAR, null);
    }

    public void setThreeCurrentUserName(String username){
        editor.putString(SHARED_KEY_CURRENTUSER_USERNAME, username);
        editor.commit();
    }

    public String getThreeCurrentUsername(){
        return mSharedPreferences.getString(SHARED_KEY_CURRENTUSER_USERNAME, null);
    }






}
